﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class page_Supplier_Manager : PageBase
{
    private static DataTable dt = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!IsPostBack)
        {
            Utility.InitUltraWebGrid.InitDisplayLayOut(this.UWGSupplier);

            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页
        //RequestCompetences = Competences.BuildCompetencesList(Competences.g);//页面权限
        base.OnLoad(e);
    }

    #endregion

    private void BindData()
    {
        dt = new DAL.Tables.tbl_Shop_Supplier().Open("", "Isuse=1", "ID asc");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "暂无您需要的数据", this.GetType().BaseType.FullName);

            return;
        }

        this.UWGSupplier.DataSource = dt;
        this.UWGSupplier.DataBind();
    } 

    protected void btnSearch_Click(object sender, EventArgs e)
    {

    }
    
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        string ID = this.SID.Value.ToString();
        if(ID != "")
        {
            Response.Redirect("Supplier_Edit.aspx?Action=Edit&ID=" + ID + "");
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("Supplier_Edit.aspx?Action=Add");
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string ID = this.SID.Value.ToString();
        if(ID != "")
        {
            DAL.Tables.tbl_Shop_Supplier Supplier = new DAL.Tables.tbl_Shop_Supplier();
            Supplier.Isuse.Value = false;
            Supplier.Update("ID="+ID);
        }

        BindData();
        this.SID.Value = "";
    }

    protected void btnOutData_Click(object sender, EventArgs e)
    {
        Utility.DataTableToExcel.DataTableToExcelAndDownload(dt, "Supplier_Manager.xls");    
    }

    protected void UWGSupplier_PageIndexChanged(object sender, Infragistics.WebUI.UltraWebGrid.PageEventArgs e)
    {
        BindData();
    }

}
